<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>销售商品统计</title>
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<style type="text/css">
			#fm {
				text-align: center;
			}
		</style>
	</head>

	<body style="padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div class="easyui-layout" data-options="fit:true" style="width: 98%;">
			<div id="searchOption" data-options="region:'north',title:'查询条件',split:true" style="height:130px;width:100%">

			</div>
			<div data-options="region:'center',split:true" style="width:100%;height: 200px;">
				<div class="easyui-panel" style="width:100%;height:100%;padding:0px;">
					<table id="dg" style="width: 100%" class="table_style">
					</table>
				</div>
			</div>
			<div id="addFrame" class="easyui-dialog" style="width:400px;height:350px;padding: 20px 30px;margin-left:;" data-options="title:'查询',closed:true">
				<form id="fm" style="margin: 0px 0px ;" method="post">
				</form>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/buildDialogSearch.js"></script>
	<script type="text/javascript">
		var globelOption = '';//保存查询参数
		var searchType = 0;
		var newData = [{
			"name": "库存开始时间",
			"type": "STOCK_DATE_START",
			"className": "easyui-datebox",
			"required": false,
			"id": "search_customer_type"
		},{
			"name": "库存结束时间",
			"type": "STOCK_DATE_END",
			"className": "easyui-datebox",
			"required": false,
			"id": "search_customer_type"
		}]
		searchType = SEARCH_INTERNAL_TYPE+ SEARCH_INTERNAL_NAME + SEARCH_STOREHOUSE_NAME;
			$('#searchOption').append(constructSearchOptionFormat(searchType, newData));
		var content = buildSearchOptions(searchType, newData);
		$("#fm").append(content);

		var toolbarType = RECEIPT_SEARCH_SYMBOL + RECEIPT_EXPORT_SYMBOL + RECEIPT_SEARCHALL_SYMBOL;
		var toolbarList = '';
		toolbarList = AddReceiptsToolBar(toolbarType, ""); /**根据用户的权限，来决定生成ToolBar的哪些功能**/
		$("#toolbar").append(toolbarList); /*在ID=toolbar的标记后面添加content中的内容*/
		//配送单位

		initCombobox();

		function initCombobox() {
			$('#search_storehouse').combobox({
				valueField: 'NAME',
				textField: 'NAME',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				editable: false,
				url: RemoteLinkAddress + "/logistics/storehouse/listall.do",
			});
			//商品类型
			$('#search_internal_type').combobox({
				valueField: 'INTERNAL_TYPE',
				textField: 'INTERNAL_TYPE',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				editable: false,
				url: RemoteLinkAddress + "/logistics/internaltradetype/listall.do",
			});
			//商品名称
			$('#search_commodity_name').combobox({
				valueField: 'INTERNAL_NAME',
				textField: 'INTERNAL_NAME',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				url: RemoteLinkAddress + "/logistics/internaltrade/listall.do",
				onChange: function(newValue, oldValue) {
					if(!isEnglish(newValue)) {
						return;
					}
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/logistics/internaltrade/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				},
			});
			$('#search_customr_name').combobox({
				valueField: 'CUSTOMER_NAME',
				textField: 'CUSTOMER_NAME',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				url: RemoteLinkAddress + '/logistics/customer/listall.do',
				onChange: function(newValue, oldValue) {
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/logistics/customer/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				}
			});
		}

		function doSearch() {
			var searchCondition = processSearchCondition(true);
			globelOption = searchCondition;
			var _url = RemoteLinkAddress + '/logistics/stock/list.do?' + searchCondition;
			getRemoteData(_url);
			$('#addFrame').dialog('close');
		}

		function closeForm() {
			$('#addFrame').dialog('close');
		}

		function searchmore() {
			$("#addFrame").dialog('open').dialog('center');
			$('#fm').form('clear');
		}

			//导出
		function exportExcel(){
			var _url = RemoteLinkAddress + '/logistics/stock/excel.do'
			if(globelOption.length > 0){
				_url += '?' + globelOption;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
			if(r) {
				$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
					type: "get",
					dataType: "json", //服务器返回的数据类型
					url: _url,
					success: function(result) {
						window.location.href = result.path;
					}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
					error: function(xhr, status, error) {
						$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}
		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: 'json',
				success: function(result) {
					$('#dg').datagrid('options').url = _url;
					$('#dg').datagrid('reload');
				},
				error: function(error) {
				}
			});
		}

		function redodata() {
			getRemoteData(RemoteLinkAddress + '/logistics/stock/list.do')
		}

		$('#dg').datagrid({
			url: RemoteLinkAddress + '/logistics/stock/list.do',
			method: 'get',
			pagination: 'true',
			fitColumns: 'false',
			rownumbers: 'true',
			singleSelect: 'true',
			height: 400,
			width: '100%',
			/*表格中的列名以及各自列名的ID*/
			columns: [
				[{
					field: 'STOREHOUSE_NAME',
					title: '库房名称',
					width: '17%',
					align: 'center'
				}, {
					field: 'INTERNAL_NAME',
					title: '内部商品名',
					width: '16%',
					align: 'center'
				}, {
					field: 'INTERNAL_TYPE',
					title: '内部商品类型',
					width: '15%',
					align: 'center'
				}, {
					field: 'STOCK',
					title: '每日库存',
					width: '15%',
					align: 'center'
				}, {
					field:'UNIT_NAME',
					title:'单位',
					width:'15%',
					align:'center'
				},{
					field: 'STOCK_DATE',
					title: '库存时间',
					width: '15%',
					align: 'center'
				},]
			]
		});
		getRemoteData(RemoteLinkAddress + '/logistics/stock/list.do')
	</script>

</html>